//
//  NSString+KeywordHighLight.m
//  LastOne
//
//  Created by dllo on 15/11/11.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "NSString+KeywordHighLight.h"

@implementation NSString (KeywordHighLight)
//输入字符串和关键字,即可输出高亮字符串
+ (NSMutableAttributedString *)KeywordHighLight:(NSString *)textString Keyword:(NSString *)keywordString
{
    //初始化文本属性
    NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:textString];
    //获取标红的位置和长度
    NSRange rang = [textString rangeOfString:keywordString];
    //设置标签文字属性
    [attributeString setAttributes:[NSMutableDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] range:rang];
    return attributeString;
}
//例如:调用
//cell.titleLabel.attributedText = [NSString KeywordHighLight:(NSString *)textString Keyword:(NSString *)keywordString];

@end
